<?
/**
 * Searching users...
 */
class UsersIterator implements IIterador{

	/**
	 * Save the result
	 * 
	 * @see search()
	 * @var integer
	 */
	private $result;

	/**
	 * Number of results
	 * @var integer
	 */
	private $num_rows=0;
	
	/**
	 * Object database connection
	 * @var MySQL
	 */
	private $MySQL;
	
	/**
	 * Inicialize the database connection
	 */
	public function __construct(){
		$this->MySQL = MySQL::get_instance();
	}
	
	
	public function total_results(){
		return $this->num_rows;
	}

	public function first(){
		mysql_data_seek($this->result, 0);
	}

	public function next(){
		$row = @mysql_fetch_row($this->result);
		if($row)
			$id = $row[0];
		else
			return null;
			
		return new User($id);
	}

	public function search($filters = array()){
		
		$query = "SELECT SQL_CALC_FOUND_ROWS users.id
				FROM users
				WHERE 
					$filter
				GROUP BY users.id
				$limit; ";
					
		$this->result = $this->MySQL->query($query);
		
		$calc_num_rows = mysql_query("SELECT FOUND_ROWS();");
		$array_num_rows = mysql_fetch_array($calc_num_rows);
		$this->num_rows = $array_num_rows[0];
	}
}
?>